﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PSE.Framework.ErrorLogging;
using System.Xml.Serialization;
using System.Xml;

namespace Sinacor.Infra.Common.ErrorLogging
{
    public abstract class LoginEnvironmentData : UserNameEnvironmentData
    {
        [XmlAttribute]
        public string SinacorCompany { get; set; }
        [XmlAttribute]
        public string SinacorModule { get; set; }
        
        protected override string ToStringOverride()
        {
            StringBuilder logData = new StringBuilder(base.ToStringOverride());

            if (!string.IsNullOrEmpty(this.SinacorCompany))
            {
                logData.AppendFormat("SinacorCompany:\t{0}", this.SinacorCompany);
                logData.AppendLine();
            }

            if (!string.IsNullOrEmpty(this.SinacorModule))
            {
                logData.AppendFormat("SinacorModule:\t{0}", this.SinacorModule);
                logData.AppendLine();
            }

            return logData.ToString();
        }

        public override void WriteTo(XmlWriter writer)
        {
            base.WriteTo(writer);

            if (!string.IsNullOrEmpty(this.SinacorCompany))
            {
                writer.WriteElementString("SinacorCompany", this.SinacorCompany);
            }

            if (!string.IsNullOrEmpty(this.SinacorModule))
            {
                writer.WriteElementString("SinacorModule", this.SinacorModule);
            }
        }
    }
}
